package com.coco.service.impl;

import com.coco.dao.RecordMapper;
import com.coco.model.RecordInfo;
import com.coco.model.RecordModel;
import com.coco.model.RecordToday;
import com.coco.service.RecordService;
import com.coco.utils.CommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author GHOSTLaycoo
 * @date 2020/4/28 - 9:39
 */
@Service
public class RecordServiceImpl implements RecordService{

    @Autowired
    private RecordMapper recordMapper;

    @Override
    public int save(RecordModel recordModel) {
        String id = UUID.randomUUID().toString();
        Date date = new Date();
        recordModel.setCreateTime(date);
        recordModel.setId(id);
        return recordMapper.save(recordModel);
    }

    @Override
    public int delete(String userId) {
        return recordMapper.delete(userId);
    }

    @Override
    public List<RecordInfo> searchRecord(String userId) {
        RecordToday recordToday = new RecordToday();
        Date startTime = CommonUtils.initDateByDay();
        Date endTime = CommonUtils.getNeedTime(23, 59, 59, 0);
        recordToday.setEndTime(endTime);
        recordToday.setStartTime(startTime);
        recordToday.setUserId(userId);
        return recordMapper.searchRecord(recordToday);
    }
}
